import axios from 'axios'
import { Message } from 'element-ui'

// create an axios instance
const serviceFile = axios.create({
  // baseURL: process.env.BASE_API, // api 的 base_url
  timeout: 30000 // request timeout
})

// request interceptor
serviceFile.interceptors.request.use(
  config => {
    return config
  },
  error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
  }
)

// response interceptor
serviceFile.interceptors.response.use(
  response => {
    // alert(3)
    return response
  }, error => {
    console.log('err' + error)// for debug
    Message({
      message: '登录连接超时（后台不能连接，请联系系统管理员）',
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  })

export default serviceFile
